package io.github.l86400.component.selenium.starter;

import io.github.l86400.component.selenium.core.exception.ErrorCode;
import io.github.l86400.component.selenium.core.web.driver.chrome.ChromeOptions;
import io.github.l86400.component.selenium.core.web.driver.manager.ChromeMemoryWebDriverManager;
import io.github.l86400.component.selenium.core.web.driver.manager.WebDriverManager;
import io.github.l86400.core.exception.BusinessException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author 86400
 * @since 2021/12/21 11:20
 */
@EnableAutoConfiguration
@EnableConfigurationProperties(SeleniumProperties.class)
public class SeleniumAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public WebDriverManager webDriverManager(SeleniumProperties seleniumProperties) {
        WebDriverManagerProperties webDriverManagerProperties = seleniumProperties.getWebDriverManager();
        switch (webDriverManagerProperties.getBrowser()) {
            case "chrome":
                ChromeOptions chromeOptions = new ChromeOptions();
                new ChromeMemoryWebDriverManager(chromeOptions);
            default:
                throw new BusinessException(ErrorCode.SELENIUM_EXCEPTION_ENUM);
        }

    }
}
